define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'qudao/adminlist/index',
                    add_url: 'qudao/adminlist/add',
                    edit_url: 'qudao/adminlist/edit',
                    del_url: 'qudao/adminlist/del',
                    multi_url: 'qudao/adminlist/multi',
                }
            });

            var table = $("#table");

            //在表格内容渲染完成后回调的事件
            table.on('post-body.bs.table', function (e, json) {
                $("tbody tr[data-index]", this).each(function () {
                    if (parseInt($("td:eq(1)", this).text()) == Config.admin.id) {
                        $("input[type=checkbox]", this).prop("disabled", true);
                    }
                });
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [{
                            field: 'state',
                            checkbox: true,
                        },
                        {
                            field: 'id',
                            title: 'ID'
                        },
                        {
                            field: 'username',
                            title: __('Username')
                        },
                        {
                            field: 'nickname',
                            title: __('Nickname'),

                        },


                        {
                            field: 'mobile',
                            title: __('Mobile')
                        },
                        {
                            field: 'alltx',
                            title: __('累计提现'),
                            operate: "="
                        },
                        {
                            field: 'money',
                            title: __('余额'),
                            operate: "="
                        },

                        {
                            field: 'status',
                            title: __("Status"),
                            searchList: {
                                "normal": __('Normal'),
                                "hidden": __('Hidden')
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [{
                                name: "ajax",
                                text: '佣金设置',
                                title: __("佣金设置"),
                                classname: "btn btn-xs btn-info  btn-priceset btn-dialog",
                                icon: "fa fa-plus",
                                refresh: true,
                                // visible:false,
                                url: "qudao/adminlist/priceset?ids={ids}",

                            }],
                        }

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        money: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        priceset: function () {
            Form.api.bindevent($("form[role=form]"));
        },

    };
    return Controller;
});